#include "GameState.h"
#include "../SGD Wrappers/SGD_InputManager.h"
#include "../SGD Wrappers/SGD_AudioManager.h"
#include "../SGD Wrappers/SGD_GraphicsManager.h"
#include "../SGD Wrappers/EntityManager.h"
#include "../SGD Wrappers/SGD_String.h"
#include "../particles/ParticleManager.h"
#include "../Game.h"
#include "CharSelect.h"
#include "../tile/TileManager.h"

#include "../source/Player.h"
#include "../source/Gorbi.h"
#include "../source/Wall.h"
#include "../source/Ball.h"
#include "../source/Ally.h"
#include "../source/PowerUp.h"
#include "../source/Cannyble.h"
#include "../anim/AnimationManager.h"

#include "../source/Runner.h"
#include "../source/Bomber.h"
#include "../source/Striker.h"
#include "../source/Tank.h"
#include "../SGD Wrappers/SGD_String.h"
#include "../Punch.h"
#include "../source/ScorpSpear.h"
#include "DodgeBomb.h"
#include "../source/Goalie.h"
#include "MainMenuState.h"
#include "../source/PathHint.h"

#define BUCKET_PLAYERS 0
#define BUCKET_ENEMIES 1
#define BUCKET_GORBI 2
#define BUCKET_BALL 3
#define BUCKET_WALLS 4
#define BUCKET_POWERUPS 5
#define BUCKET_PUNCH 6
#define BUCKET_SPEAR 7
#define BUCKET_GOALIE 8
#define BUCKET_PHINTS 9

CGameState* CGameState::GetInstance(void)
{
	static CGameState s_Instance;
	return &s_Instance;
}

void CGameState::Enter(void)
{
	m_bMiniGame = false;

	if (m_bmap1 == true)
		CTileManager::GetInstance()->LoadLevel("Level1.xml");
	else
		CTileManager::GetInstance()->LoadLevel("Level4.xml");


	pParticleSys = CParticleManager::GetInstance();

	Game::GetInstance()->SetMiniGame(false);

	m_TopWall = new CWall;
	m_TopWall->SetPosition({ 0, -100 });
	m_TopWall->SetSize({ Game::GetInstance()->GetScreenWidth(), 100 });
	m_TopWall->SetColor({ 255, 0, 0, 0 });
	m_TopWall->SetImpentrable(true);
	m_pEntities->AddEntity(m_TopWall, BUCKET_WALLS);

	m_BotWall = new CWall;
	m_BotWall->SetPosition({ 0, Game::GetInstance()->GetScreenHeight() - 1 });

	m_BotWall->SetSize({ Game::GetInstance()->GetScreenWidth(), 100 });
	m_BotWall->SetColor({ 255, 0, 0, 0 });
	m_BotWall->SetImpentrable(true);
	m_pEntities->AddEntity(m_BotWall, BUCKET_WALLS);


	m_LeftWall = new CWall;
	m_LeftWall->SetPosition({ -100, 0 });
	m_LeftWall->SetSize({ 100, Game::GetInstance()->GetScreenHeight() });
	m_LeftWall->SetColor({ 0, 0, 0, 0 });
	m_LeftWall->SetImpentrable(true);
	m_pEntities->AddEntity(m_LeftWall, BUCKET_WALLS);

	m_RightWall = new CWall;
	m_RightWall->SetPosition({ Game::GetInstance()->GetScreenWidth(), 0 });

	m_RightWall->SetSize({ 100, Game::GetInstance()->GetScreenHeight() });
	m_RightWall->SetColor({ 0, 0, 0, 0 });
	m_RightWall->SetImpentrable(true);
	m_pEntities->AddEntity(m_RightWall, BUCKET_WALLS);


	testBall = dynamic_cast<CBall*>(CreateBall(CTileManager::GetInstance()->SpawnEntity(m_nEntitySpawnIndex), { 32, 32 }));
	m_nEntitySpawnIndex++;
	testBall->SetColor({ 255, 0, 255 });
	testBall->m_bMiniGame = false;
	m_pEntities->AddEntity(testBall, BUCKET_BALL);

	m_pPlayer1->SetBall(nullptr);
	m_pPlayer2->SetBall(nullptr);
	m_pPlayer3->SetBall(nullptr);
	m_pPlayer4->SetBall(nullptr);



	testGorbi = new CGorbi;
	testGorbi->SetPosition(CTileManager::GetInstance()->SpawnEntity(5));
	testGorbi->SetSize({ 32, 32 });
	testGorbi->SetColor({ 0, 255, 255 });
	testGorbi->SetHomePos(testGorbi->GetPosition());

	testGorbi->SetBall(testBall);
	testGorbi->SetBallHome(testBall->GetPosition());
	m_pEntities->AddEntity(testGorbi, BUCKET_GORBI);

	//testAlly = new CAlly;
	//testAlly->SetPosition({ 100, 200 });
	//testAlly->SetSize({ 32, 32 });
	//testAlly->SetColor({ 255, 255, 0 });
	//m_pEntities->AddEntity(testAlly, BUCKET_PLAYERS);







	SGD::AudioManager::GetInstance()->StopAudio(Game::GetInstance()->GetMenuMusic());
	SGD::AudioManager::GetInstance()->PlayAudio(Game::GetInstance()->GetGameMusic(), true);

	CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(testGorbi), "BossFront");
	CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(testGorbi)->currAnimation);
	//End slate cursor stuff
	m_cursor = 0;
	m_bWin = false;



	if (m_pPlayer1->GetTeam() == true)
	{
		m_pPlayer1->SetPosition(CTileManager::GetInstance()->SpawnEntity(1));

		if (m_pPlayer2->GetTeam() == true)
		{
			m_pPlayer1->SetTeamMate(m_pPlayer2);
			m_pPlayer2->SetTeamMate(m_pPlayer1);

			m_pPlayer2->SetPosition(CTileManager::GetInstance()->SpawnEntity(2));
		}
		else if (m_pPlayer3->GetTeam() == true)
		{
			m_pPlayer1->SetTeamMate(m_pPlayer3);
			m_pPlayer3->SetTeamMate(m_pPlayer1);

			m_pPlayer3->SetPosition(CTileManager::GetInstance()->SpawnEntity(2));
		}
		else if (m_pPlayer4->GetTeam() == true)
		{
			m_pPlayer1->SetTeamMate(m_pPlayer4);
			m_pPlayer4->SetTeamMate(m_pPlayer1);

			m_pPlayer4->SetPosition(CTileManager::GetInstance()->SpawnEntity(2));
		}
	}
	else if (m_pPlayer1->GetTeam() == false)
	{
		m_pPlayer1->SetPosition(CTileManager::GetInstance()->SpawnEntity(3));

		if (m_pPlayer2->GetTeam() == false)
		{
			m_pPlayer1->SetTeamMate(m_pPlayer2);
			m_pPlayer2->SetTeamMate(m_pPlayer1);

			m_pPlayer2->SetPosition(CTileManager::GetInstance()->SpawnEntity(4));
		}
		else if (m_pPlayer3->GetTeam() == false)
		{
			m_pPlayer1->SetTeamMate(m_pPlayer3);
			m_pPlayer3->SetTeamMate(m_pPlayer1);

			m_pPlayer3->SetPosition(CTileManager::GetInstance()->SpawnEntity(4));
		}
		else if (m_pPlayer4->GetTeam() == false)
		{
			m_pPlayer1->SetTeamMate(m_pPlayer4);
			m_pPlayer4->SetTeamMate(m_pPlayer1);

			m_pPlayer4->SetPosition(CTileManager::GetInstance()->SpawnEntity(4));
		}
	}

	if (m_pPlayer1->GetTeamMate() == m_pPlayer2)
	{
		m_pPlayer3->SetTeamMate(m_pPlayer4);
		m_pPlayer4->SetTeamMate(m_pPlayer3);

		if (m_pPlayer3->GetTeam() == true)
		{
			m_pPlayer3->SetPosition(CTileManager::GetInstance()->SpawnEntity(1));
			m_pPlayer4->SetPosition(CTileManager::GetInstance()->SpawnEntity(2));
		}
		else
		{
			m_pPlayer3->SetPosition(CTileManager::GetInstance()->SpawnEntity(3));
			m_pPlayer4->SetPosition(CTileManager::GetInstance()->SpawnEntity(4));
		}
	}
	else if (m_pPlayer1->GetTeamMate() == m_pPlayer3)
	{
		m_pPlayer2->SetTeamMate(m_pPlayer4);
		m_pPlayer4->SetTeamMate(m_pPlayer2);

		if (m_pPlayer2->GetTeam() == true)
		{
			m_pPlayer2->SetPosition(CTileManager::GetInstance()->SpawnEntity(1));
			m_pPlayer4->SetPosition(CTileManager::GetInstance()->SpawnEntity(2));
		}
		else
		{
			m_pPlayer2->SetPosition(CTileManager::GetInstance()->SpawnEntity(3));
			m_pPlayer4->SetPosition(CTileManager::GetInstance()->SpawnEntity(4));
		}

	}
	else if (m_pPlayer1->GetTeamMate() == m_pPlayer4)
	{
		m_pPlayer2->SetTeamMate(m_pPlayer3);
		m_pPlayer3->SetTeamMate(m_pPlayer2);

		if (m_pPlayer2->GetTeam() == true)
		{
			m_pPlayer2->SetPosition(CTileManager::GetInstance()->SpawnEntity(1));
			m_pPlayer3->SetPosition(CTileManager::GetInstance()->SpawnEntity(2));
		}
		else
		{
			m_pPlayer2->SetPosition(CTileManager::GetInstance()->SpawnEntity(3));
			m_pPlayer3->SetPosition(CTileManager::GetInstance()->SpawnEntity(4));
		}
	}

	m_pPlayer1->SetHomePos(m_pPlayer1->GetPosition());
	m_pPlayer2->SetHomePos(m_pPlayer2->GetPosition());
	m_pPlayer3->SetHomePos(m_pPlayer3->GetPosition());
	m_pPlayer4->SetHomePos(m_pPlayer4->GetPosition());

	m_nEntitySpawnIndex = 6;

	for (int numTallWalls = 0; numTallWalls < CTileManager::GetInstance()->GetCount(0); numTallWalls++)
	{
		testWall = dynamic_cast<CWall*>(CreateWall(CTileManager::GetInstance()->SpawnEntity(m_nEntitySpawnIndex), { 32, 32 }, true));
		testWall->SetColor({ 150, 255, 150 });
		m_pEntities->AddEntity(testWall, BUCKET_WALLS);
		testWall->Release();
		m_nEntitySpawnIndex++;
	}

	for (int numShortWalls = 0; numShortWalls < CTileManager::GetInstance()->GetCount(1); numShortWalls++)
	{
		testWall = dynamic_cast<CWall*>(CreateWall(CTileManager::GetInstance()->SpawnEntity(m_nEntitySpawnIndex), { 32, 32 }, false));
		testWall->SetColor({ 100, 255, 100 });
		m_pEntities->AddEntity(testWall, BUCKET_WALLS);

		testWall->Release();
		m_nEntitySpawnIndex++;
	}

	/*CPathHint* tempPhint = new CPathHint;
	tempPhint->SetPosition({ 320, 128 });
	tempPhint->SetSize({ 160, 32 });
	tempPhint->SetColor({ 127, 255, 255, 255 });
	m_pEntities->AddEntity(tempPhint, BUCKET_PHINTS);
	tempPhint->Release();

	tempPhint = new CPathHint;
	tempPhint->SetPosition({ 320, 416 });
	tempPhint->SetSize({ 160, 32 });
	tempPhint->SetColor({ 127, 255, 255, 255 });
	m_pEntities->AddEntity(tempPhint, BUCKET_PHINTS);
	tempPhint->Release();

	tempPhint = new CPathHint;
	tempPhint->SetPosition({ 320, 224 });
	tempPhint->SetSize({ 32, 96 });
	tempPhint->SetColor({ 127, 255, 255, 255 });
	m_pEntities->AddEntity(tempPhint, BUCKET_PHINTS);
	tempPhint->Release();

	tempPhint = new CPathHint;
	tempPhint->SetPosition({ 448, 224 });
	tempPhint->SetSize({ 32, 96 });
	tempPhint->SetColor({ 127, 255, 255, 255 });
	m_pEntities->AddEntity(tempPhint, BUCKET_PHINTS);
	tempPhint->Release();*/

	int numPatrollers = 0;
	for (int numEnemies = 0; numEnemies < CTileManager::GetInstance()->GetCount(2); numEnemies++)
	{
		testCannyble = dynamic_cast<CCannyble*>(CreateCannyble(CTileManager::GetInstance()->SpawnEntity(m_nEntitySpawnIndex), { 32, 32 }));
		testCannyble->SetColor({ 255, 255, 100 });

		if (CTileManager::GetInstance()->GetNumWaypoints(numEnemies) > 0)
		{
			testCannyble->AddWaypoints(testCannyble->GetHomePos());
			for (int numWaypoints = 0; numWaypoints < CTileManager::GetInstance()->GetNumWaypoints(numEnemies); numWaypoints++)
			{
				testCannyble->AddWaypoints(CTileManager::GetInstance()->GetWaypoints(numPatrollers));
			}
			testCannyble->SwitchStates(CAI::PATROL_STATE);
			numPatrollers++;
		}

		m_pEntities->AddEntity(testCannyble, BUCKET_ENEMIES);
		m_Cannys.push_back(testCannyble);
		testCannyble->Release();
		m_nEntitySpawnIndex++;
	}

	/*testAlly->SetPlayer(m_pPlayer4);
	testAlly->SetBall(testBall);
	testAlly->SetPosition(testAlly->GetPlayer()->GetPosition());
	testAlly->SetSize(m_pPlayer4->GetSize());*/
}

void CGameState::Exit(void)

{
	pParticleSys->Terminate();
	pParticleSys->DeleteInstance();

	m_nEntitySpawnIndex = 0;

	CTileManager::GetInstance()->UnloadLevel();
	CTileManager::DeleteInstance();

	if (!m_bMiniGame)
	{
		CAnimationManager::GetInstance()->RemoveAll();
		CAnimationManager::GetInstance()->DeleteInstance();
	}


	m_nPlayerNumber = 1;
	SGD::AudioManager::GetInstance()->StopAudio(Game::GetInstance()->GetGameMusic());
	SGD::AudioManager::GetInstance()->PlayAudio(Game::GetInstance()->GetMenuMusic(), true);

	m_nBlueScore = 0;
	m_nRedScore = 0;
	m_uGameTime = 300;
	m_bmap1 = true;

	if (m_pPlayer1 != nullptr)
	{
		m_pPlayer1->Release();
		m_pPlayer1 = nullptr;
	}

	if (m_pPlayer2 != nullptr)
	{
		m_pPlayer2->Release();
		m_pPlayer2 = nullptr;
	}

	if (m_pPlayer3 != nullptr)
	{
		m_pPlayer3->Release();
		m_pPlayer3 = nullptr;
	}

	if (m_pPlayer4 != nullptr)
	{
		m_pPlayer4->Release();
		m_pPlayer4 = nullptr;
	}

	if (testGorbi != nullptr)
	{
		testGorbi->Release();
		testGorbi = nullptr;
	}

	if (testAlly != nullptr)
	{
		testAlly->Release();
		testAlly = nullptr;
	}

	if (m_BotWall != nullptr)
	{
		m_BotWall->Release();
		m_BotWall = nullptr;
	}

	if (m_LeftWall != nullptr)
	{
		m_LeftWall->Release();
		m_LeftWall = nullptr;
	}

	if (m_TopWall != nullptr)
	{
		m_TopWall->Release();
		m_TopWall = nullptr;
	}

	if (m_RightWall != nullptr)
	{
		m_RightWall->Release();
		m_RightWall = nullptr;
	}

	if (testBall != nullptr)
	{
		testBall->Release();
		testBall = nullptr;
	}


	if (m_pEntities != nullptr)
	{
		m_pEntities->RemoveAll();
		delete m_pEntities;
		m_pEntities = nullptr;
	}



}

bool CGameState::Input(void)
{
	if (m_bScored == false || m_bPause == false)
	{
		SGD::InputManager* pInput = SGD::InputManager::GetInstance();
		SGD::AudioManager* pAudio = SGD::AudioManager::GetInstance();

		//End game slate stuff vvv
		if (m_bWin)
		{
			if (SGD::InputManager::GetInstance()->IsKeyPressed(SGD::Key::DownArrow) == true)
			{
				if (GetCursor() < 1)
				{
					SetCursor(GetCursor() + 1);
				}
			}

			if (SGD::InputManager::GetInstance()->IsKeyPressed(SGD::Key::UpArrow) == true)
			{
				if (GetCursor() > 0)
				{
					SetCursor(GetCursor() - 1);
				}
			}

			if (SGD::InputManager::GetInstance()->IsKeyPressed(SGD::Key::Enter) == true)
			{
				if (GetCursor() == 0)
				{
					//Replay
					ResetGame();

				}
				else if (GetCursor() == 1)
				{
					//Return to main menu
					Game::GetInstance()->ChangeState(CMainMenuState::GetInstance());
				}
			}
		}
		//End game slate stuff ^^^
		if (pInput->IsKeyPressed(SGD::Key::Escape) == true || pInput->IsButtonPressed(0, 1) == true)
		{
			Game::GetInstance()->ChangeState(CCharSelect::GetInstance());
			return true;
		}


		if (pInput->IsKeyPressed(SGD::Key::Q) == true)
			m_uGameTime = 155;


		if (pInput->IsKeyPressed(SGD::Key::M) == true)
		{
			this->SetRedScore(5);
		}
		if (pInput->IsKeyPressed(SGD::Key::T) == true)
			testBall->SetPosition({ 400, 216 });
	}
	return true;
}

void CGameState::Update(float elapsedTime)
{
	pParticleSys->UpdateAll(elapsedTime);
	CAnimationManager::GetInstance()->UpdateAll(elapsedTime);
	if (m_nBlueScore == 5 || m_nRedScore == 5)
		m_bWin = true;

	if (m_bScored == true)
	{
		m_fWinTimer -= elapsedTime;
		if (m_fWinTimer <= 0)
		{
			m_bScored = false;


			m_fWinTimer = 5;
			if (hBlueScorePar != nullptr)
			{

				CParticleManager::GetInstance()->DeleteEmitter(hBlueScorePar);
				hBlueScorePar = nullptr;
			}
			if (hRedScorePar != nullptr)
			{
				CParticleManager::GetInstance()->DeleteEmitter(hRedScorePar);
				hRedScorePar = nullptr;
			}
		}
	}
	else if (m_bScored == false || m_bPause == false)
	{
		CTileManager::GetInstance()->Update(0.15f);

		if (m_bWin == false)
			m_pEntities->UpdateAll(elapsedTime);

		m_pEntities->CheckCollisions(BUCKET_PLAYERS, BUCKET_PLAYERS);
		m_pEntities->CheckCollisions(BUCKET_PLAYERS, BUCKET_BALL);
		m_pEntities->CheckCollisions(BUCKET_PLAYERS, BUCKET_GORBI);
		m_pEntities->CheckCollisions(BUCKET_PLAYERS, BUCKET_WALLS);
		m_pEntities->CheckCollisions(BUCKET_PLAYERS, BUCKET_POWERUPS);
		m_pEntities->CheckCollisions(BUCKET_PLAYERS, BUCKET_ENEMIES);
		m_pEntities->CheckCollisions(BUCKET_GORBI, BUCKET_WALLS);
		m_pEntities->CheckCollisions(BUCKET_PLAYERS, BUCKET_PUNCH);
		m_pEntities->CheckCollisions(BUCKET_BALL, BUCKET_WALLS);
		m_pEntities->CheckCollisions(BUCKET_ENEMIES, BUCKET_WALLS);
		m_pEntities->CheckCollisions(BUCKET_SPEAR, BUCKET_PLAYERS);
		m_pEntities->CheckCollisions(BUCKET_SPEAR, BUCKET_BALL);
		m_pEntities->CheckCollisions(BUCKET_SPEAR, BUCKET_ENEMIES);
		m_pEntities->CheckCollisions(BUCKET_SPEAR, BUCKET_WALLS);
		m_pEntities->CheckCollisions(BUCKET_BALL, BUCKET_GOALIE);
		m_pEntities->CheckCollisions(BUCKET_PLAYERS, BUCKET_GOALIE);
		m_pEntities->CheckCollisions(BUCKET_PLAYERS, BUCKET_PHINTS);
		m_pEntities->CheckCollisions(BUCKET_GORBI, BUCKET_BALL);
		m_pEntities->CheckCollisions(BUCKET_GORBI, BUCKET_PUNCH);

		CTileManager::GetInstance()->BallCollision({ testBall->GetPosition(), testBall->GetSize() }, testBall);

	}


	m_uGameTime -= elapsedTime;
	m_fPowerUpTimer -= elapsedTime;

	pParticleSys->UpdateAll(elapsedTime);


	if (m_fPowerUpTimer <= 0)
	{

		if (m_nPowerupnumber > 4)
			m_nPowerupnumber = 0;

		if (m_nPowerupnumber == 0)
			CreatePowerup({ 300, 200 }, { 32, 32 }, CPowerUp::PUP_GOALIE);
		else if (m_nPowerupnumber == 1)
			CreatePowerup({ 300, 200 }, { 32, 32 }, CPowerUp::PUP_NOAGGRO);
		else if (m_nPowerupnumber == 2)
			CreatePowerup({ 300, 200 }, { 32, 32 }, CPowerUp::PUP_ABILITYCHARGE);
		else if (m_nPowerupnumber == 3)
			CreatePowerup({ 300, 200 }, { 32, 32 }, CPowerUp::PUP_KNOCKBACK);
		else if (m_nPowerupnumber == 4)
			CreatePowerup({ 300, 200 }, { 32, 32 }, CPowerUp::PUP_STEAL);


		m_nPowerupnumber++;


		m_fPowerUpTimer = 10;
	}

	if (m_uGameTime <= 150 && m_uGameTime >= 149)
	{
		m_pPlayer1->SetAmIInAMiniGame(true);
		m_pPlayer2->SetAmIInAMiniGame(true);
		m_pPlayer3->SetAmIInAMiniGame(true);
		m_pPlayer4->SetAmIInAMiniGame(true);
		m_bMiniGame = true;

		CDodgeBomb::GetInstance()->PassPlayers(m_pPlayer1, 1);
		CDodgeBomb::GetInstance()->PassPlayers(m_pPlayer2, 2);
		CDodgeBomb::GetInstance()->PassPlayers(m_pPlayer3, 3);
		CDodgeBomb::GetInstance()->PassPlayers(m_pPlayer4, 4);
		CDodgeBomb::GetInstance()->PassData(m_nRedScore, m_nBlueScore);

		Game::GetInstance()->ChangeState(CDodgeBomb::GetInstance());
	}


	/*if (m_bWin == true && SGD::InputManager::GetInstance()->IsAnyKeyPressed() == true)
	{

	m_bWin = false;
	Game::GetInstance()->ChangeState(CCharSelect::GetInstance());
	}*/
}

void CGameState::Render(void)
{
	CTileManager::GetInstance()->Render();

	if (m_bWin == false)
		m_pEntities->RenderAll();

	SGD::OStringStream String;
	String << m_pPlayer1->GetCurrStamina();
	SGD::GraphicsManager::GetInstance()->DrawString(String.str().c_str(), { 0, 0 }, { 0, 0, 0 });

	SGD::OStringStream tOString;
	tOString << m_pPlayer3->GetCurrStamina();
	SGD::GraphicsManager::GetInstance()->DrawString(tOString.str().c_str(), { 750, 0 }, { 0, 0, 0 });

	SGD::OStringStream time;
	time << (int)m_uGameTime;
	SGD::GraphicsManager::GetInstance()->DrawString(time.str().c_str(), { 400, 0 }, { 0, 0, 0 });

	SGD::OStringStream redScore;
	redScore << m_nRedScore;
	SGD::GraphicsManager::GetInstance()->DrawString(redScore.str().c_str(), { 370, 0 }, { 255, 0, 0 });

	SGD::OStringStream blueScore;
	blueScore << m_nBlueScore;
	SGD::GraphicsManager::GetInstance()->DrawString(blueScore.str().c_str(), { 450, 0 }, { 0, 0, 255 });

	SGD::OStringStream p1Charge;
	p1Charge << m_pPlayer1->GetCharge();
	SGD::GraphicsManager::GetInstance()->DrawString(p1Charge.str().c_str(), { 0, 500 }, { 0, 0, 0 });

	m_pEntities->RenderAll();

	pParticleSys->RenderAll();



	if (m_bScored == true)
		SGD::GraphicsManager::GetInstance()->DrawString("YOU'VE SCORED!", { Game::GetInstance()->GetScreenWidth() / 2, Game::GetInstance()->GetScreenHeight() / 2 }, { 0, 255, 0 });

	if (m_bWin == true)
	{
		//End game slate stuff vvv
		SGD::GraphicsManager::GetInstance()->DrawRectangle(SGD::Rectangle(SGD::Point{ 100, 100 }, SGD::Point{ 700, 500 }),
		{ 155, 255, 0, 255 },
		{ 255, 255, 100, 100 });


		SGD::GraphicsManager::GetInstance()->DrawString("Replay?", { 250, 250 }, { 255, 255, 255 });


		SGD::GraphicsManager::GetInstance()->DrawString("Return to main menu?", { 250, 350 }, { 255, 255, 255 });


		SGD::GraphicsManager::GetInstance()->DrawString(">>                               <<", { 225.0f, (float)((GetCursor() * 100) + 250) });

		//End game slate stuff ^^^
		if (m_nBlueScore > m_nRedScore)
		{
			SGD::GraphicsManager::GetInstance()->DrawString("BLUE WINS!", { Game::GetInstance()->GetScreenWidth() / 2, Game::GetInstance()->GetScreenHeight() / 2 }, { 0, 0, 255 });
		}
		else
		{
			SGD::GraphicsManager::GetInstance()->DrawString("RED WINS!", { Game::GetInstance()->GetScreenWidth() / 2, Game::GetInstance()->GetScreenHeight() / 2 }, { 255, 0, 0 });
		}
	}
	CAnimationManager::GetInstance()->RenderAll();
}

void CGameState::BlueScore()
{
	//CParticleManager * pPart = CParticleManager::GetInstance();

	//pPart->v_LoadedEmit[0]->m_poiPos = { 300, 300 };

	if (m_bScored == false)
	{
		m_nBlueScore++;


		if (m_pPlayer1->GetEmitter() != nullptr)
		{
			CParticleManager::GetInstance()->DeleteEmitter(m_pPlayer1->GetEmitter());
			m_pPlayer1->SetEmitter(nullptr);
		}
		if (m_pPlayer2->GetEmitter() != nullptr)
		{
			CParticleManager::GetInstance()->DeleteEmitter(m_pPlayer2->GetEmitter());
			m_pPlayer2->SetEmitter(nullptr);
		}
		if (m_pPlayer3->GetEmitter() != nullptr)
		{
			CParticleManager::GetInstance()->DeleteEmitter(m_pPlayer3->GetEmitter());
			m_pPlayer3->SetEmitter(nullptr);
		}
		if (m_pPlayer4->GetEmitter() != nullptr)
		{
			CParticleManager::GetInstance()->DeleteEmitter(m_pPlayer4->GetEmitter());
			m_pPlayer4->SetEmitter(nullptr);
		}
		//hBlueScorePar = pPart->CreateEmitter(&SGD::Point(50.0f, 300.0f), "ParticleFile2.xml", CEmitter::STEADY);

		if (!SGD::AudioManager::GetInstance()->IsAudioPlaying(Game::GetInstance()->GetScoreSound()))
			SGD::AudioManager::GetInstance()->PlayAudio(Game::GetInstance()->GetScoreSound());

		ResetGame();
		m_bScored = true;
	}
}

void CGameState::RedScore()
{
	//CParticleManager * pPart = CParticleManager::GetInstance();


	//pPart->v_LoadedEmit[0]->m_poiPos = { 300, 300 };


	if (m_bScored == false)
	{
		m_nRedScore++;


		if (m_pPlayer1->GetEmitter() != nullptr)
		{
			CParticleManager::GetInstance()->DeleteEmitter(m_pPlayer1->GetEmitter());
			m_pPlayer1->SetEmitter(nullptr);
		}
		if (m_pPlayer2->GetEmitter() != nullptr)
		{
			CParticleManager::GetInstance()->DeleteEmitter(m_pPlayer2->GetEmitter());
			m_pPlayer2->SetEmitter(nullptr);
		}
		if (m_pPlayer3->GetEmitter() != nullptr)
		{
			CParticleManager::GetInstance()->DeleteEmitter(m_pPlayer3->GetEmitter());
			m_pPlayer3->SetEmitter(nullptr);
		}
		if (m_pPlayer4->GetEmitter() != nullptr)
		{
			CParticleManager::GetInstance()->DeleteEmitter(m_pPlayer4->GetEmitter());
			m_pPlayer4->SetEmitter(nullptr);
		}

		if (!SGD::AudioManager::GetInstance()->IsAudioPlaying(Game::GetInstance()->GetScoreSound()))
			SGD::AudioManager::GetInstance()->PlayAudio(Game::GetInstance()->GetScoreSound());


		//hRedScorePar = pPart->CreateEmitter(&SGD::Point(300.0f, 300.0f), "ParticleFile2.xml", CEmitter::STEADY);
		ResetGame();
		m_bScored = true;
	}

}

//TODO: Reset what you need to reset! 
void CGameState::ResetGame()
{
	testBall->SetPosition(CTileManager::GetInstance()->SpawnEntity(0));
	testBall->ToggleActive(true);

	m_pPlayer1->SetPosition(m_pPlayer1->GetHomePos());
	m_pPlayer1->SetCarrying(false);
	m_pPlayer1->SetBall(nullptr);

	m_pPlayer2->SetPosition(m_pPlayer2->GetHomePos());
	m_pPlayer2->SetCarrying(false);
	m_pPlayer2->SetBall(nullptr);

	m_pPlayer3->SetPosition(m_pPlayer3->GetHomePos());
	m_pPlayer3->SetCarrying(false);
	m_pPlayer3->SetBall(nullptr);

	m_pPlayer4->SetPosition(m_pPlayer4->GetHomePos());
	m_pPlayer4->SetCarrying(false);
	m_pPlayer4->SetBall(nullptr);

	testBall->SetOwner(nullptr);
	testBall->SetHeld(false);

	//testAlly->SetPosition(testAlly->GetPlayer()->GetPosition());
	for (int index = 0; index < CTileManager::GetInstance()->GetCount(2); index++)
	{
		m_Cannys[index]->SetPosition(m_Cannys[index]->GetHomePos());

		if (CTileManager::GetInstance()->GetNumWaypoints(index) > 0)
			m_Cannys[index]->SwitchStates(CAI::PATROL_STATE);
		else
			m_Cannys[index]->SwitchStates(CAI::IDLE_STATE);

		m_Cannys[index]->SetVelocity({ 0, 0 });
		m_Cannys[index]->SetTarget(nullptr);
	}

	testGorbi->SetTarget(nullptr);
	testGorbi->SetPosition(testGorbi->GetHomePos());
	testGorbi->SetVelocity({ 0, 0 });
	testGorbi->SwitchStates(CAI::IDLE_STATE);

	if (m_bWin == true)
	{
		m_nRedScore = m_nBlueScore = 0;
		m_uGameTime = 300.0f;
	}
	m_bScored = true;
	m_bWin = false;

	// TODO: Anything missing?
}

Entity* CGameState::CreatePunch(Entity* pOwner) const
{
	CPunch* p = new CPunch;
	p->SetOwner(pOwner);
	if (dynamic_cast<CPlayer*>(pOwner)->GetHeading())
	{
		p->SetPosition(SGD::Point{ pOwner->GetPosition().x + pOwner->GetSize().width, pOwner->GetPosition().y + 30 });
	}
	else
		p->SetPosition(SGD::Point{ pOwner->GetPosition().x - 40, pOwner->GetPosition().y + 30 });

	p->SetHeading(dynamic_cast<CPlayer*>(pOwner)->GetHeading());
	p->SetRotation(pOwner->GetRotation());
	p->SetSize({ 30, 8 });

	p->SetPunchTimer(0.1f);
	m_pEntities->AddEntity(p, BUCKET_PUNCH);
	return p;


}

void CGameState::DeleteEntity(Entity* e)
{
	m_pEntities->RemoveEntity(e);
}



void CGameState::CreatePlayer(SGD::Point position, SGD::Size size, int type, bool team, int controller, SGD::Rectangle prmRect)
{
	if (m_pEntities == nullptr)
	{
		m_pEntities = new EntityManager;
		CAnimationManager::GetInstance()->Initialize();
	}


	if (m_nPlayerNumber == 1)
	{

		if (type == 1)
			m_pPlayer1 = new CRunner;
		else if (type == 2)
			m_pPlayer1 = new CBomber;
		else if (type == 3)
			m_pPlayer1 = new CStriker;
		else
			m_pPlayer1 = new CTank;


		m_pPlayer1->SetSize(size);
		m_pPlayer1->SetVelocity({ 0, 0 });
		m_pPlayer1->SetControllernumber(controller);
		m_pPlayer1->SetTeam(team);

		if (team == true)
			CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer1), "runnerIdleR");
		else
			CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer1), "runnerIdleB");

		CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer1)->currAnimation);

		SGD::Size temp = { m_pPlayer1->currAnimation.GetCurrPassiveRect().right, m_pPlayer1->currAnimation.GetCurrPassiveRect().bottom };
		m_pPlayer1->SetSize(temp);
		m_pPlayer1->SetAbilityRect(prmRect);
		m_pEntities->AddEntity(m_pPlayer1, BUCKET_PLAYERS);
	}

	if (m_nPlayerNumber == 2)
	{
		if (type == 1)
			m_pPlayer2 = new CRunner;
		else if (type == 2)
			m_pPlayer2 = new CBomber;
		else if (type == 3)
			m_pPlayer2 = new CStriker;
		else
			m_pPlayer2 = new CTank;


		m_pPlayer2->SetSize(size);
		m_pPlayer2->SetVelocity({ 0, 0 });
		m_pPlayer2->SetControllernumber(controller);
		m_pPlayer2->SetTeam(team);

		if (team == true)
			CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer2), "bomberIdleR");
		else
			CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer2), "bomberIdleB");
		CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer2)->currAnimation);

		SGD::Size temp = { m_pPlayer2->currAnimation.GetCurrPassiveRect().right, m_pPlayer2->currAnimation.GetCurrPassiveRect().bottom };
		m_pPlayer2->SetSize(temp);

		m_pPlayer2->SetAbilityRect(prmRect);


		m_pEntities->AddEntity(m_pPlayer2, BUCKET_PLAYERS);
	}

	if (m_nPlayerNumber == 3)
	{
		if (type == 1)
			m_pPlayer3 = new CRunner;
		else if (type == 2)
			m_pPlayer3 = new CBomber;
		else if (type == 3)
			m_pPlayer3 = new CStriker;
		else
			m_pPlayer3 = new CTank;


		m_pPlayer3->SetSize(size);
		m_pPlayer3->SetVelocity({ 0, 0 });
		m_pPlayer3->SetControllernumber(controller);
		m_pPlayer3->SetTeam(team);

		if (team == true)
			CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer3), "strikerIdleR");
		else
			CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer3), "strikerIdleB");
		CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer3)->currAnimation);

		SGD::Size temp = { m_pPlayer3->currAnimation.GetCurrPassiveRect().right, m_pPlayer3->currAnimation.GetCurrPassiveRect().bottom };
		m_pPlayer3->SetSize(temp);

		m_pPlayer3->SetAbilityRect(prmRect);

		m_pEntities->AddEntity(m_pPlayer3, BUCKET_PLAYERS);
	}

	if (m_nPlayerNumber == 4)
	{
		if (type == 1)
			m_pPlayer4 = new CRunner;
		else if (type == 2)
			m_pPlayer4 = new CBomber;
		else if (type == 3)
			m_pPlayer4 = new CStriker;
		else
			m_pPlayer4 = new CTank;


		m_pPlayer4->SetSize(size);
		m_pPlayer4->SetVelocity({ 0, 0 });
		m_pPlayer4->SetControllernumber(controller);
		m_pPlayer4->SetTeam(team);

		if (team == true)
			CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer4), "tankIdleR");
		else
			CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer4), "tankIdleB");
		CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer4)->currAnimation);

		SGD::Size temp = { m_pPlayer4->currAnimation.GetCurrPassiveRect().right, m_pPlayer4->currAnimation.GetCurrPassiveRect().bottom };
		m_pPlayer4->SetSize(temp);

		m_pPlayer4->SetAbilityRect(prmRect);

		m_pEntities->AddEntity(m_pPlayer4, BUCKET_PLAYERS);
	}

	m_nPlayerNumber++;
}

Entity* CGameState::CreateCannyble(SGD::Point position, SGD::Size size)
{
	CCannyble* tempCannyble = new CCannyble;

	tempCannyble->SetPosition(position);
	tempCannyble->SetHomePos(position);
	tempCannyble->SetSize(size);
	tempCannyble->SetVelocity({ 0, 0 });

	return tempCannyble;
}

Entity* CGameState::CreateBall(SGD::Point position, SGD::Size size)
{
	CBall* tempBall = new CBall;

	tempBall->SetPosition(position);
	tempBall->SetSize(size);
	tempBall->SetVelocity({ 0, 0 });

	return tempBall;
}

Entity* CGameState::CreateWall(SGD::Point position, SGD::Size size, bool highLow)
{
	CWall* tempWall = new CWall;

	tempWall->SetHeight(highLow);
	tempWall->SetPosition(position);
	tempWall->SetSize(size);
	tempWall->SetVelocity({ 0, 0 });
	tempWall->ToggleActive(true);

	return tempWall;
}

Entity* CGameState::CreateGorbi(SGD::Point position, SGD::Size size)
{
	CGorbi* tempGorbi = new CGorbi;

	tempGorbi->SetPosition(position);
	tempGorbi->SetHomePos(position);
	tempGorbi->SetSize(size);
	tempGorbi->SetVelocity({ 0, 0 });

	return tempGorbi;
}

Entity* CGameState::CreateAlly(SGD::Point position, SGD::Size size)
{
	CAlly* tempAlly = new CAlly;

	tempAlly->SetPosition(position);
	tempAlly->SetSize(size);
	tempAlly->SetVelocity({ 0, 0 });

	return tempAlly;
}

void CGameState::CreatePowerup(SGD::Point position, SGD::Size size, int type)
{
	CPowerUp* tempPowerup = new CPowerUp;

	tempPowerup->SetType(type);
	tempPowerup->SetPosition(position);

	//CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(tempPowerup), "pickupAnim");
	//CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(tempPowerup)->currAnimation);
	//SGD::Size temp = { tempPowerup->currAnimation.GetCurrPassiveRect().right, tempPowerup->currAnimation.GetCurrPassiveRect().bottom };
	//tempPowerup->SetSize(temp);
	tempPowerup->SetSize(size);
	tempPowerup->SetVelocity({ 0, 0 });


	tempPowerup->SetColor({ 255, 100, 255 });
	m_pEntities->AddEntity(tempPowerup, BUCKET_POWERUPS);
	tempPowerup->Release();
}

void CGameState::PassPlayers(CPlayer* p, int playernumber)
{
	if (m_pEntities == nullptr)
	{
		m_pEntities = new EntityManager;
		CAnimationManager::GetInstance()->RemoveAll();
		CAnimationManager::GetInstance()->Initialize();
	}

	if (dynamic_cast<CRunner*>(p))
	{
		if (playernumber == 1)
		{


			m_pPlayer1 = new CRunner;
			*m_pPlayer1 = *p;
			m_pPlayer1->Release();
			m_pEntities->AddEntity(m_pPlayer1, BUCKET_PLAYERS);

			if (m_pPlayer1->GetTeam() == true)
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer1), "runnerIdleR");
			else
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer1), "runnerIdleB");

			CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer1)->currAnimation);
		}
		else if (playernumber == 2)
		{
			m_pPlayer2 = new CRunner;
			*m_pPlayer2 = *p;
			m_pPlayer2->Release();
			m_pEntities->AddEntity(m_pPlayer2, BUCKET_PLAYERS);

			if (m_pPlayer2->GetTeam() == true)
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer2), "runnerIdleR");
			else
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer2), "runnerIdleB");

			CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer2)->currAnimation);
		}
		else if (playernumber == 3)
		{
			m_pPlayer3 = new CRunner;
			*m_pPlayer3 = *p;
			m_pPlayer3->Release();
			m_pEntities->AddEntity(m_pPlayer3, BUCKET_PLAYERS);

			if (m_pPlayer3->GetTeam() == true)
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer3), "runnerIdleR");
			else
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer3), "runnerIdleB");

			CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer3)->currAnimation);
		}
		else if (playernumber == 4)
		{
			m_pPlayer4 = new CRunner;
			*m_pPlayer4 = *p;
			m_pPlayer4->Release();
			m_pEntities->AddEntity(m_pPlayer4, BUCKET_PLAYERS);

			if (m_pPlayer4->GetTeam() == true)
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer4), "runnerIdleR");
			else
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer4), "runnerIdleB");

			CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer4)->currAnimation);
		}


	}
	else if (dynamic_cast<CBomber*>(p))
	{
		if (playernumber == 1)
		{
			m_pPlayer1 = new CBomber;
			*m_pPlayer1 = *p;
			m_pPlayer1->Release();
			m_pEntities->AddEntity(m_pPlayer1, BUCKET_PLAYERS);

			if (m_pPlayer1->GetTeam() == true)
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer1), "bomberIdleR");
			else
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer1), "bomberIdleB");

			CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer1)->currAnimation);
		}
		else if (playernumber == 2)
		{
			m_pPlayer2 = new CBomber;
			*m_pPlayer2 = *p;
			m_pPlayer2->Release();
			m_pEntities->AddEntity(m_pPlayer2, BUCKET_PLAYERS);

			if (m_pPlayer2->GetTeam() == true)
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer2), "bomberIdleR");
			else
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer2), "bomberIdleB");

			CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer2)->currAnimation);
		}
		else if (playernumber == 3)
		{
			m_pPlayer3 = new CBomber;
			*m_pPlayer3 = *p;
			m_pPlayer3->Release();
			m_pEntities->AddEntity(m_pPlayer3, BUCKET_PLAYERS);

			if (m_pPlayer3->GetTeam() == true)
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer3), "bomberIdleR");
			else
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer3), "bomberIdleB");

			CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer3)->currAnimation);
		}
		else if (playernumber == 4)
		{
			m_pPlayer4 = new CBomber;
			*m_pPlayer4 = *p;
			m_pPlayer4->Release();
			m_pEntities->AddEntity(m_pPlayer4, BUCKET_PLAYERS);

			if (m_pPlayer4->GetTeam() == true)
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer4), "bomberIdleR");
			else
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer4), "bomberIdleB");

			CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer4)->currAnimation);
		}
	}
	else if (dynamic_cast<CStriker*>(p))
	{
		if (playernumber == 1)
		{
			m_pPlayer1 = new CStriker;
			*m_pPlayer1 = *p;
			m_pPlayer1->Release();
			m_pEntities->AddEntity(m_pPlayer1, BUCKET_PLAYERS);

			if (m_pPlayer1->GetTeam() == true)
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer1), "strikerIdleR");
			else
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer1), "strikerIdleB");

			CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer1)->currAnimation);
		}
		else if (playernumber == 2)
		{
			m_pPlayer2 = new CStriker;
			*m_pPlayer2 = *p;
			m_pPlayer2->Release();
			m_pEntities->AddEntity(m_pPlayer2, BUCKET_PLAYERS);

			if (m_pPlayer2->GetTeam() == true)
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer2), "strikerIdleR");
			else
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer2), "strikerIdleB");

			CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer2)->currAnimation);
		}
		else if (playernumber == 3)
		{
			m_pPlayer3 = new CStriker;
			*m_pPlayer3 = *p;
			m_pPlayer3->Release();
			m_pEntities->AddEntity(m_pPlayer3, BUCKET_PLAYERS);

			if (m_pPlayer3->GetTeam() == true)
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer3), "strikerIdleR");
			else
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer3), "strikerIdleB");

			CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer3)->currAnimation);
		}
		else if (playernumber == 4)
		{
			m_pPlayer4 = new CStriker;
			*m_pPlayer4 = *p;
			m_pPlayer4->Release();
			m_pEntities->AddEntity(m_pPlayer4, BUCKET_PLAYERS);

			if (m_pPlayer4->GetTeam() == true)
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer4), "strikerIdleR");
			else
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer4), "strikerIdleB");

			CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer4)->currAnimation);
		}
	}
	else if (dynamic_cast<CTank*>(p))
	{
		if (playernumber == 1)
		{
			m_pPlayer1 = new CTank;
			*m_pPlayer1 = *p;
			m_pPlayer1->Release();
			m_pEntities->AddEntity(m_pPlayer1, BUCKET_PLAYERS);

			if (m_pPlayer1->GetTeam() == true)
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer1), "tankIdleR");
			else
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer1), "tankIdleB");

			CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer1)->currAnimation);
		}
		else if (playernumber == 2)
		{
			m_pPlayer2 = new CTank;
			*m_pPlayer2 = *p;
			m_pPlayer2->Release();
			m_pEntities->AddEntity(m_pPlayer2, BUCKET_PLAYERS);

			if (m_pPlayer2->GetTeam() == true)
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer2), "tankIdleR");
			else
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer2), "tankIdleB");

			CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer2)->currAnimation);
		}
		else if (playernumber == 3)
		{
			m_pPlayer3 = new CTank;
			*m_pPlayer3 = *p;
			m_pPlayer3->Release();
			m_pEntities->AddEntity(m_pPlayer3, BUCKET_PLAYERS);

			if (m_pPlayer3->GetTeam() == true)
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer3), "tankIdleR");
			else
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer3), "tankIdleB");

			CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer3)->currAnimation);
		}
		else if (playernumber == 4)
		{
			m_pPlayer4 = new CTank;
			*m_pPlayer4 = *p;
			m_pPlayer4->Release();
			m_pEntities->AddEntity(m_pPlayer4, BUCKET_PLAYERS);

			if (m_pPlayer4->GetTeam() == true)
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer4), "tankIdleR");
			else
				CAnimationManager::GetInstance()->SetOwner(reinterpret_cast<Entity*>(m_pPlayer4), "tankIdleB");

			CAnimationManager::GetInstance()->AddAnim(&reinterpret_cast<Entity*>(m_pPlayer4)->currAnimation);
		}
	}
}

void CGameState::PassData(int redscore, int bluescore)
{
	m_nRedScore = redscore;
	m_nBlueScore = bluescore;


	m_uGameTime = 147;
}

Entity* CGameState::CreateScorpSpear(Entity* pOwner, int level)
{
	CScorpSpear* tempSpear = new CScorpSpear(pOwner);

	tempSpear->SetPosition(pOwner->GetPosition());

	SGD::Vector direction = pOwner->GetVelocity();
	direction.Normalize();

	if (level == 1)
	{
		tempSpear->SetVelocity(direction * 100);
	}
	else if (level == 2)
	{
		tempSpear->SetVelocity(direction * 150);
	}
	else if (level == 3)
	{
		tempSpear->SetVelocity(direction * 200);
	}

	tempSpear->SetLevel(level);
	tempSpear->SetSize({ 10, 10 });
	tempSpear->SetColor({ 0, 0, 0 });
	m_pEntities->AddEntity(tempSpear, BUCKET_SPEAR);

	return tempSpear;
}

Entity* CGameState::CreateGoalie(Entity* pOwner)
{
	CGoalie* tempGoalie = new CGoalie;

	tempGoalie->SetSize({ 32, 64 });

	tempGoalie->SetOwner(pOwner);

	if (dynamic_cast<CPlayer*>(pOwner)->GetTeam() == false)
		tempGoalie->SetPosition({ 101, 224 });
	else
		tempGoalie->SetPosition({ 672, 224 });

	m_pEntities->AddEntity(tempGoalie, BUCKET_GOALIE);

	return tempGoalie;
}